$(function () {
    let old_data;
    //初始化当前用户信息
    $.ajax({
        url: BigNew.user_detail,
        success(data) {
            old_data = data.data;
            $('#form .username').val(old_data.username);
            $('#form .nickname').val(old_data.nickname);
            $('#form .email').val(old_data.email);
            $('#form .user_pic').attr('src',old_data.userPic)
            $('#form .password').val(old_data.password);
        }
    })
 
       //图片预览
       $('#exampleInputFile').on('change', function () {
        if (this.files[0]) {
            let url = URL.createObjectURL(this.files[0]);
            $('.form-group .user_pic').attr('src', url);
        }
       
    })
//将编辑好的信息提交到服务器
    $('.form-group .btn-edit').click(function (e) {
        e.preventDefault();
        let data = new FormData($('#form')[0]);
        
      
        
        $.ajax({
            type: 'post',
            url: BigNew.user_edit,
            data,
            contentType: false,
            processData:false,
            success(backData) {
                if (backData.code == 200) {
                    $('#edit_Modal .modal-body p').text(backData.msg);
                    $('#edit_Modal').modal('show');
                    
                }
            }
           
        });

 //刷新用户信息
        $('#edit_Modal').on('hidden.bs.modal', function (e) {
            e.preventDefault();
        $.ajax({
                type: 'get',
                url: BigNew.user_info,
            success(data) {
                console.log(data);
                    window.parent.$('.sider .user_info img,.sider .header_bar img').attr('src', data.data.userPic);
                    window.parent.$('.sider .user_info span').html("欢迎&nbsp;&nbsp;" + data.data.nickname);
                }
              });
          })

    })
})